import request from '@/utils/request'

// ==================== 新闻资讯 ====================

// 获取新闻列表
export function getNewsList(params) {
  return request({
    url: '/v1/news',
    method: 'get',
    params
  })
}

// 获取新闻详情
export function getNewsDetail(id) {
  return request({
    url: `/v1/news/${id}`,
    method: 'get'
  })
}

// 获取热门新闻
export function getHotNews(limit = 10) {
  return request({
    url: '/v1/news/hot',
    method: 'get',
    params: { limit }
  })
}

// 获取推荐新闻
export function getRecommendNews(limit = 10) {
  return request({
    url: '/v1/news/recommend',
    method: 'get',
    params: { limit }
  })
}

// 获取置顶新闻
export function getTopNews(categoryId, limit = 5) {
  return request({
    url: '/v1/news/top',
    method: 'get',
    params: { categoryId, limit }
  })
}

// 搜索新闻
export function searchNews(keyword, params) {
  return request({
    url: '/v1/news/search',
    method: 'get',
    params: { keyword, ...params }
  })
}

// 按分类获取新闻
export function getNewsByCategory(categoryId, params) {
  return request({
    url: `/v1/news/category/${categoryId}`,
    method: 'get',
    params
  })
}

// 点赞新闻
export function likeNews(newsId) {
  return request({
    url: `/v1/news/${newsId}/like`,
    method: 'post'
  })
}

// 收藏新闻
export function favoriteNews(newsId) {
  return request({
    url: `/v1/news/${newsId}/favorite`,
    method: 'post'
  })
}

// 取消收藏
export function unfavoriteNews(newsId) {
  return request({
    url: `/v1/news/${newsId}/unfavorite`,
    method: 'post'
  })
}

// 获取收藏新闻
export function getFavoriteNews(params) {
  return request({
    url: '/v1/news/favorites',
    method: 'get',
    params
  })
}

// 增加阅读量
export function increaseReadCount(newsId) {
  return request({
    url: `/v1/news/${newsId}/read`,
    method: 'post'
  })
}

// ==================== 新闻分类 ====================

// 获取新闻分类
export function getNewsCategories() {
  return request({
    url: '/v1/news-categories',
    method: 'get'
  })
}

// 获取分类树
export function getNewsCategoryTree() {
  return request({
    url: '/v1/news-categories/tree',
    method: 'get'
  })
}

// ==================== 新闻评论 ====================

// 获取新闻评论
export function getNewsComments(newsId, params) {
  return request({
    url: `/v1/news-comments/news/${newsId}`,
    method: 'get',
    params
  })
}

// 添加评论
export function addNewsComment(data) {
  return request({
    url: '/v1/news-comments',
    method: 'post',
    data
  })
}

// 回复评论
export function replyNewsComment(commentId, content) {
  return request({
    url: `/v1/news-comments/${commentId}/reply`,
    method: 'post',
    data: { content }
  })
}

// 点赞评论
export function likeNewsComment(commentId) {
  return request({
    url: `/v1/news-comments/${commentId}/like`,
    method: 'post'
  })
}

// 删除评论
export function deleteNewsComment(commentId) {
  return request({
    url: `/v1/news-comments/${commentId}`,
    method: 'delete'
  })
}

// ==================== 新闻标签 ====================

// 获取新闻标签
export function getNewsTags() {
  return request({
    url: '/v1/news-tags',
    method: 'get'
  })
}

// 按标签获取新闻
export function getNewsByTag(tagId, params) {
  return request({
    url: `/v1/news/tag/${tagId}`,
    method: 'get',
    params
  })
}

// ==================== 新闻统计 ====================

// 获取新闻统计
export function getNewsStatistics(newsId) {
  return request({
    url: `/v1/news/${newsId}/statistics`,
    method: 'get'
  })
}

// 获取阅读历史
export function getReadHistory(params) {
  return request({
    url: '/v1/news/read-history',
    method: 'get',
    params
  })
}
